<?
if (!defined('SMF'))
	die('Hacking attempt...');

global $ore_rate, $organics_rate, $goods_rate, $energy_rate;
global $ore_limit, $organics_limit, $goods_limit, $energy_limit;

// Begin update ore levels in all ports.
$message .= 'Adding ore to all commodities ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_ore = port_ore + ({float:ore_rate} * {int:multiplier})
	WHERE port_type="ore"
	AND port_ore < {int:ore_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'ore_rate' => $ore_rate,
		'ore_limit' => $ore_limit
	)
);

$message .= 'Adding ore to all ore ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_ore = port_ore + ({float:ore_rate} * {int:multiplier})
	WHERE port_type != "special"
	AND port_type != "none"
	AND port_ore < {int:ore_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'ore_rate' => $ore_rate,
		'ore_limit' => $ore_limit
	)
);

$message .= 'Ensuring minimum ore levels are 0...<br>';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_ore = 0
	WHERE port_ore < 0',
	array(
		'db_universe' => $dbtables['universe']
	)
);
// End update ore levels in all ports.

// Begin update organics levels in all ports.
$message .= 'Adding organics to all commodities ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_organics = port_organics + ({float:organics_rate} * {int:multiplier})
	WHERE port_type = "organics"
	AND port_organics < {int:organics_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'organics_rate' => $organics_rate,
		'organics_limit' => $organics_limit
	)
);

$message .= 'Adding organics to all organics ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_organics = port_organics + ({float:organics_rate} * {int:multiplier})
	WHERE port_type != "special"
	AND port_type != "none"
	AND port_organics < {int:organics_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'organics_rate' => $organics_rate,
		'organics_limit' => $organics_limit
	)
);

$message .= 'Ensuring minimum organics levels are 0...<br>';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_organics = 0
	WHERE port_organics < 0',
	array(
		'db_universe' => $dbtables['universe']
	)
);
// End update organics levels in all ports.

// Begin update goods levels in all ports.
$message .= 'Adding goods to all commodities ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_goods = port_goods + ({float:goods_rate} * {int:multiplier})
	WHERE port_type = "goods"
	AND port_goods < {int:goods_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'goods_rate' => $goods_rate,
		'goods_limit' => $goods_limit
	)
);

$message .= 'Adding goods to all goods ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_goods = port_goods + ({float:goods_rate} * {int:multiplier})
	WHERE port_type != "special"
	AND port_type != "none"
	AND port_goods < {int:goods_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'goods_rate' => $goods_rate,
		'goods_limit' => $goods_limit
	)
);

$message .= 'Ensuring minimum goods levels are 0...<br>';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_goods = 0
	WHERE port_goods < 0',
	array(
		'db_universe' => $dbtables['universe']
	)
);
// End update goods levels in all ports.

// Begin update energy levels in all ports.
$message .= 'Adding energy to all commodities ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_energy = port_energy + ({float:energy_rate} * {int:multiplier})
	WHERE port_type = "energy"
	AND port_energy < {int:energy_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'energy_rate' => $energy_rate,
		'energy_limit' => $energy_limit
	)
);

$message .= 'Adding energy to all energy ports...';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_energy = port_energy + ({float:energy_rate} * {int:multiplier})
	WHERE port_type != "special"
	AND port_type != "none"
	AND port_energy < {int:energy_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'multiplier' => $multiplier,
		'energy_rate' => $energy_rate,
		'energy_limit' => $energy_limit
	)
);

$message .= 'Ensuring minimum energy levels are 0...<br>';
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_energy = 0
	WHERE port_energy < 0',
	array(
		'db_universe' => $dbtables['universe']
	)
);
// End update energy levels in all ports.

$message .= '<br>';

// Ensure commodity levels do not exceed the established limits.
$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_energy = {int:energy_limit}
	WHERE port_energy > {int:energy_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'energy_limit' => $energy_limit
	)
);

$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_goods = {int:goods_limit}
	WHERE port_goods > {int:goods_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'goods_limit' => $goods_limit
	)
);

$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_organics = {int:organics_limit}
	WHERE port_organics > {int:organics_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'organics_limit' => $organics_limit
	)
);

$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_universe}
	SET port_ore = {int:ore_limit}
	WHERE port_ore > {int:ore_limit}',
	array(
		'db_universe' => $dbtables['universe'],
		'ore_limit' => $ore_limit
	)
);
?>
